<template>
    <div class="login-container">
      <el-form 
        :model="loginForm" 
        :rules="loginRules" 
        ref="loginForm" 
        label-width="0" 
        class="login-form">
        <h3 class="title">监管机构登录</h3>
        
        <el-form-item prop="username">
          <el-input 
            v-model="loginForm.username" 
            placeholder="请输入用户名" 
            prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input 
            type="password" 
            v-model="loginForm.password" 
            placeholder="请输入密码" 
            prefix-icon="el-icon-lock"></el-input>
        </el-form-item>
  
        <el-form-item prop="captcha">
          <el-col :span="16">
            <el-input 
              v-model="loginForm.captcha" 
              placeholder="请输入验证码" 
              prefix-icon="el-icon-view"></el-input>
          </el-col>
          <el-col :span="8">
            <img 
              :src="captchaUrl" 
              @click="refreshCaptcha" 
              alt="验证码" 
              class="captcha-img">
          </el-col>
        </el-form-item>
  
        <el-form-item>
          <el-button type="primary" native-type="submit" @click="handleLogin">登录</el-button>
          <el-button>重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        loginForm: {
          username: '',
          password: '',
          captcha: '',
        },
        loginRules: {
          username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
          password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
          captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
        },
        captchaUrl: 'https://web-tel.oss-cn-beijing.aliyuncs.com/Snipaste_2024-01-21_11-23-44.png', // 假设这是获取验证码图片的API
      };
    },
    methods: {
      handleLogin() {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            const currentRoute = this.$router.currentRoute;
      if (currentRoute.path !== "/sa") {
        this.$router.push("/sa");
      }
          } else {
            console.log('登录信息验证失败');
          }
        });
      },
      submitLoginForm() {
        // 这里应发起一个包含用户名、密码和验证码的登录请求
        // 并处理返回结果，例如：
       
      },
      refreshCaptcha() {
        // 刷新验证码图片
      },
    },
  };
  </script>
  
  <style scoped>
  .login-container {
    width: 400px;
    margin: 0 auto;
    padding-top: 100px;
  }
  
  .title {
    text-align: center;
    font-size: 24px;
    color: #333;
    margin-bottom: 20px;
  }
  .captcha-img {
  cursor: pointer;
  width: 100px; /* 设置验证码图片宽度 */
  height: 40px; /* 设置验证码图片高度 */
}
</style>